package com.eascs.cloudFile.service.impl;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;

import com.alibaba.dubbo.config.annotation.Service;
import com.eascs.cloudFile.dao.CloudFilesDao;
import com.eascs.cloudFile.entity.CloudDatalist;
import com.eascs.cloudFile.service.WebCloudFileService;
import com.eascs.cloudFile.vo.WebCloudFileVo;
import com.eascs.web.sso.User;
import com.eascs.web.sso.UserHolder;

/**
 * Web端云文档接口实现类
 * 
 * @author user
 *
 */
@Service
public class WebCloudFileServiceImpl implements WebCloudFileService {

	@Autowired
	CloudFilesDao cloudFilesDao;

	/**
	 * 查询客户附件
	 * 
	 * @param webCloudFileVo
	 * @return
	 */
	@Override
	public List<CloudDatalist> queryCloudDatas(WebCloudFileVo webCloudFileVo) {
		List<CloudDatalist> cloudFiles = new ArrayList<>();
		User user = UserHolder.getUser();
		if (user.isSuperAdministrator()) {
			cloudFiles = cloudFilesDao.findCloudFilesBySuperAdministrator(webCloudFileVo.getCustomerId(), webCloudFileVo.getOriginalName());
		} else {
			List<Object[]> list = cloudFilesDao.getManagerIdAndCreateId(webCloudFileVo.getCustomerId());
			if (list != null && list.size() != 0) {
				cloudFiles = cloudFilesDao.findCloudFiles(webCloudFileVo.getCustomerId(), webCloudFileVo.getOriginalName(), list.get(0)[0].toString(), list.get(0)[1].toString());
			}
		}
		return cloudFiles;
	}

}
